<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>首页三</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        .top-panel {
            border: 1px solid #eceff9;
            border-radius: 5px;
            text-align: center;
        }
        .top-panel > .layui-card-body{
            height: 60px;
        }
        .top-panel-number{
            line-height:60px;
            font-size: 30px;
            border-right:1px solid #eceff9;
        }
        .top-panel-tips{
            line-height:30px;
            font-size: 12px
        }
    </style>
</head>
<body>
<!--<div class="layuimini-container">-->
<div class="layuimini-main">

    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs12 layui-col-md12">
            <div id="echarts-records" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
        </div>
    </div>


    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs12 layui-col-md6">
            <div id="echarts-dataset" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
        </div>
        <div class="layui-col-xs12 layui-col-md6">
            <div id="echarts-pies" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
        </div>
    </div>


</div>
<!--</div>-->
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['layer', 'echarts'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            echarts = layui.echarts;

        /**
         * 报表功能
         */
        var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden');


        //  发送异步请求  获取折线图的数据
        $.get("/echarts/line",function (response) {
            if (response.code==0){
                let  dte = response.data
                var optionRecords = {
                    title: {
                        text: '近五年招生总人数-报表图'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    legend: {
                        data: dte.map(function(item) { return item.year; })
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data:  dte.map(function(item) { return item.year; })
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series: {
                        data: dte.map(function(item) { return item.value; }),
                        type: 'line'
                    }

                };
                echartsRecords.setOption(optionRecords);
            }

        })



        /**
         * 玫瑰图表
         */
        var echartsPies = echarts.init(document.getElementById('echarts-pies'), 'walden');

        //  发送异步请求 获取每个专业的总人数
        $.get('/echarts/rose',function (response) {

            if (response.code==0){
                let  dt = response.data
                var optionPies = {
                    title: {
                        text: '各专业人数-玫瑰图',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: dt.map(function(item) { return item.name; })
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            roseType: 'radius',
                            data: dt,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                echartsPies.setOption(optionPies)
            }
        })

      ;


        /**
         * 柱状图
         */
        var echartsDataset = echarts.init(document.getElementById('echarts-dataset'), 'walden');


        /*
        *  [
                    { name: '专业1', male: 100, female: 120 },
                    { name: '专业2', male: 150, female: 160 },
                    { name: '专业3', male: 120, female: 80 },
                    { name: '专业4', male: 310, female: 180 }
          ];
        *
        *
        * */

        //  发送请求  获取数据库中男生女生的占比  异步
        $.get('/echarts/bar',function (response) {
            if (response.code==0){
                // 假设的数据
                let data =  response.data
                // 图标配置项
                var optionDataset = {
                    title: {
                        text: '各专业男女生人数-柱状图',
                    },
                    tooltip: { },
                    legend: {
                        data: ['男生', '女生']
                    },
                    xAxis: {
                        type: 'category',
                        data: data.map(function(item) { return item.name; })
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '男生',
                            type: 'bar',
                            data: data.map(function(item) { return item.male; })
                        },
                        {
                            name: '女生',
                            type: 'bar',
                            data: data.map(function(item) { return item.female; })
                        }
                    ]
                };
                echartsDataset.setOption(optionDataset);
            }
        })




        // echarts 窗口缩放自适应
        window.onresize = function () {
            echartsRecords.resize();
        }

    });
</script>
</body>
</html>
